// pages/forum/informationDetail/informationDetail.js
Page({

 
  data: {
    flag:1,        //评论按钮的状态 1：点赞前   0：点赞后
    color:1,      //底部栏点赞按钮状态
    heart:1,       //底部栏喜欢按钮状态
    star:1,        //收藏按钮
    flag01:1,   //举报按钮
    comment:1,   //评论
  },

  // ---------------数据加载模块 start-------------------
  onLoad: function (options) {
    var resource = JSON.parse(options.resource);
    var rsid = resource.rsid;
    //console.log(answer);
    this.setData({
      resource:resource,
      rsid:rsid,
    })
    this.getResourceComment();
  },

  onReachBottom: function() {
    this.getResourceComment();  // 下拉重新获取用户评论
  },

  // ---------------数据加载模块 end-------------------
  

  // --------------功能模块 start-----------------------
  getResourceComment:function(){
    var rsid = this.data.rsid;
    //console.log("rsid:"+rsid);
    var mark = 'getResourceComment'
    wx.request({
      url: 'http://localhost:8080/youYanZaiXian/ForumServlet',
      method: 'POST',
      data:{
        rsid:rsid,
        mark:mark,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded',
        'Accept': 'application/json'
      },
      success: (res)=>{
        var rscList = res.data.data.rscList;
        this.setData({
          resourceCommentList:rscList,
        })
        //console.log(this.data.resourceCommentList)
      }
    });
  },

  inputRscComment:function(e){
    var rscComment = e.detail.value;
    var rsid = e.currentTarget.dataset.rsid
    //console.log("rscComment:"+rscComment);
    //console.log("rsid:"+rsid);
    this.setData({
      rscComment:rscComment,
      rsid:rsid,
    })
    this.sendRscComment();
  },

  sendRscComment:function(){
    var mark = 'sendRscComment';
    var rscComment = this.data.rscComment;
    //console.log(acComment)
    var rsid = this.data.rsid;
    var userid =  getApp().globalData.userid;
    wx.request({
      url: 'http://localhost:8080/youYanZaiXian/ForumServlet',
      method: 'POST',
      data:{
        mark:mark,
        rscComment:rscComment,
        rsid:rsid,
        userid:userid,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
        'Accept': 'application/json'
      },
      success: (res)=>{
        var suc = res.data.data.suc;
        if(suc==1){
          wx.showToast({
            title: '评论成功',
            icon: 'success',
            duration: 2000
          })
        }else{
          wx.showToast({
            title: '评论失败',
            icon: 'error',
            duration: 2000
          })
        }
      }
    });
  },


  //评论点赞
  reply:function(){
    if(this.data.flag){
      this.setData({
        flag:0,
        zanNum01:Number(this.data.zanNum01+1)
      })
    }else{
      this.setData({
        flag:1,
        zanNum01:Number(this.data.zanNum01-1)
      })
    }
    
  },

  //底部栏点赞
  goodNumChange:function(){
    if(this.data.color){
      this.setData({
        color:0,
        goodNum:Number(this.data.goodNum+1)
      })
    }else{
      this.setData({
        color:1,
        goodNum:Number(this.data.goodNum-1)
      })
    }
    
  },

  //底部栏喜欢按钮
  heartNumChange:function(){
    if(this.data.heart){
      this.setData({
        heart:0,
        heartNum:Number(this.data.heartNum+1)
      })
    }else{
      this.setData({
        heart:1,
        heartNum:Number(this.data.heartNum-1)
      })
    }
  },

  //底部栏收藏按钮
  starNumChange:function(){
    if(this.data.star){
      this.setData({
        star:0,
        starNum:Number(this.data.starNum+1)
      })
    }else{
      this.setData({
        star:1,
        starNum:Number(this.data.starNum-1)
      })
    }
  },

  //举报
  dislikeNumChange:function(){
    if(this.data.flag01){
      this.setData({
        flag01:0,
        // starNum:Number(this.data.starNum+1)
      })
    }else{
      this.setData({
        flag01:1,
        // starNum:Number(this.data.starNum-1)
      })
    }
  },

  //点击评论图标弹出评论框
  discussAction:function(e){
    // console.log('点击评论')
    // wx.showToast({
    //   title: '评论成功',
    //   icon:'none'
    // })
    this.setData({
      discussShow:true
    })
  },

  //点击发送按钮收起评论框
  send:function(){
    this.setData({
      discussShow:false,
      comment:0,
      commentNum:Number(this.data.commentNum+1)
    })
  },
  // --------------功能模块 end-----------------------

})


/***
 *      ┌─┐       ┌─┐ + +
 *   ┌──┘ ┴───────┘ ┴──┐++
 *   │                 │
 *   │       ───       │++ + + +
 *   ███████───███████ │+
 *   │                 │+
 *   │       ─┴─       │
 *   │                 │
 *   └───┐         ┌───┘
 *       │         │
 *       │         │   + +
 *       │         │
 *       │         └──────────────┐
 *       │                        │
 *       │                        ├─┐
 *       │                        ┌─┘
 *       │                        │
 *       └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
 *         │ ─┤ ─┤       │ ─┤ ─┤
 *         └──┴──┘       └──┴──┘  + + + +
 *                神兽保佑
 *               代码无BUG!
 */